<#--noinspection ALL-->
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
    <#if hasQuery>
      <div v-if="searchToggle">
        <!-- 搜索栏 -->
        <#if queryColumns??>
          <#list queryColumns as column>
            <#if column.queryType != 'BetWeen'>
        <label class="el-form-item-label"><#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if></label>
        <el-input v-model="query.${column.changeColumnName}" clearable placeholder="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>" style="width: 185px;" class="filter-item" @keyup.enter="fetchList" />
            </#if>
          </#list>
        </#if>
  <#if betweens??>
    <#list betweens as column>
      <#if column.queryType = 'BetWeen'>
        <el-date-picker
                v-model="query.${column.changeColumnName}"
                value-format="YYYY-MM-DD HH:mm:ss"
                type="datetimerange"
                range-separator="至"
                start-placeholder="${column.changeColumnName}开始"
                end-placeholder="${column.changeColumnName}结束"
                class="filter-item"
        />
      </#if>
    </#list>
  </#if>
        <rr-operation></rr-operation>
      </div>
    </#if>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crud-operation></crud-operation>
    </div>
      <!--表格渲染-->
    <el-table v-el-adaptive="{bottomOffset: bottomOffset}" height="100" ref="table" v-loading="tableLoading" :data="tableData" border style="width: 100%" @selection-change="selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <#if columns??>
          <#list columns as column>
            <#if column.columnShow>
          <#if (column.dictName)?? && (column.dictName) != "">
        <el-table-column prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>">
          <template v-slot="{row}">
            {{ dict.label.${column.dictName}[row.${column.changeColumnName}] }}
          </template>
        </el-table-column>
          <#elseif column.columnType != 'Timestamp'>
        <el-table-column prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>" />
                <#else>
        <el-table-column prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>">
          <template v-slot="{row}">
            <span>{{ row.${column.changeColumnName} }}</span>
          </template>
        </el-table-column>
                </#if>
            </#if>
            </#list>
        </#if>
        <el-table-column v-permission="permission.edit.concat(permission.remove)" label="操作"
        width="150px"
        align="center">
          <template v-slot="{row}">
            <ud-operation :data="row"></ud-operation>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination></pagination>

      <!--表单组件-->
    <div v-el-drag-dialog>
      <el-dialog :close-on-click-modal="false" v-model="dialog.visible"
                 :title="dialog.title" width="500px">
        <el-form ref="formRef" :model="form" <#if isNotNullColumns??>:rules="rules"</#if> size="small" label-width="80px">
    <#if columns??>
      <#list columns as column>
        <#if column.formShow>
          <el-form-item label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>"<#if column.istNotNull> prop="${column.changeColumnName}"</#if>>
            <#if column.formType = 'Input'>
            <el-input v-model="form.${column.changeColumnName}" style="width: 370px;" />
            <#elseif column.formType = 'Textarea'>
            <el-input v-model="form.${column.changeColumnName}" :rows="3" type="textarea" style="width: 370px;" />
            <#elseif column.formType = 'Radio'>
              <#if (column.dictName)?? && (column.dictName)!="">
            <el-radio v-model="form.${column.changeColumnName}" v-for="item in dict.${column.dictName}" :key="item.id" :label="item.value">{{ item.label }}</el-radio>
              <#else>
                未设置字典，请手动设置 Radio
              </#if>
            <#elseif column.formType = 'Select'>
              <#if (column.dictName)?? && (column.dictName)!="">
            <el-select v-model="form.${column.changeColumnName}" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.${column.dictName}"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
              <#else>
            未设置字典，请手动设置 Select
              </#if>
            <#else>
            <el-date-picker v-model="form.${column.changeColumnName}" type="datetime" value-format="YYYY-MM-DD HH:mm:ss" style="width: 370px;" />
            </#if>
          </el-form-item>
        </#if>
      </#list>
    </#if>
        </el-form>
        <template v-slot:footer class="dialog-footer">
          <el-button @click="dialog.visible = false">关闭</el-button>
          <el-button type="primary" :loading="dialog.status === DIALOG_STATUS.PROCESSING" @click="submitCE">确认
          </el-button>
        </template>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import useCrud from "@crud/useCrud"
import udOperation from "@crud/UD.operation"
import rrOperation from "@crud/RR.operation"
import crudOperation from "@crud/CRUD.operation"
import pagination from "@crud/Pagination"
import api from '@/api/${changeClassName}'

export default {
  name: '${className}',
  components: { pagination, crudOperation, rrOperation, udOperation },
  <#if hasDict>
  dicts: [<#if hasDict??><#list dicts as dict>'${dict}'<#if dict_has_next>, </#if></#list></#if>],
  </#if>

  setup() {
    return {
      permission: {
        create: ['${changeClassName}:save'],
        edit: ['${changeClassName}:update'],
        remove: ['${changeClassName}:remove']
      },
      ...useCrud({
        title: '${apiAlias}',
        defaultForm: {<#if columns??><#list columns as column>${column.changeColumnName}: null<#if column_has_next>, </#if></#list></#if>},
        methods: {...api}
        <#if pkChangeColName != 'id'>
        , idField: '${pkChangeColName}'
        </#if>
      })
    }
  },

  data() {
    return {
      rules: {
        <#if isNotNullColumns??>
        <#list isNotNullColumns as column>
        <#if column.istNotNull>
        ${column.changeColumnName}: [
          { required: true, message: '<#if column.remark != ''>${column.remark}</#if>不能为空', trigger: 'blur' }
        ]<#if column_has_next>,</#if>
        </#if>
        </#list>
        </#if>
      }<#if hasQuery>,
      queryTypeOptions: [
        <#if queryColumns??>
        <#list queryColumns as column>
        <#if column.queryType != 'BetWeen'>
        { key: '${column.changeColumnName}', display_name: '<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>' }<#if column_has_next>,</#if>
        </#if>
        </#list>
        </#if>
      ]
      </#if>
    }
  }
}
</script>

<style scoped>

</style>
